<template>
  <div class="dialog-bind">
    <el-dialog :visible.sync="dialogVisible" width="500px" :close-on-click-modal="false" :close-on-press-escape	='false'
               title="解绑邮箱" center>
      <div class="content">
        <h1>确定要解绑邮箱{{row.emailAddr}}吗?</h1>
        <p>邮箱解绑后将导致：</p>
        <p>1、邮箱里没有此邮箱账号。</p>
        <p>2、相关邮件将不保留。</p>
      </div>
      <div slot="footer" class="dialog-footer" align="right">
        <el-button @click="dialogVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="submit" size="mini" :loading="loading">{{loading?'解绑中':'确 定'}}
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
    import {del} from "@/api/mail/admin/mail-set";
    import {mapState} from 'vuex'
    export default {
        name: "DialogBind",
        props: ['currentEmail'],
        data() {
            return {
                dialogVisible: false,
                row: {
                    emailAddr:''
                },
                loading:false
            }
        },
        computed: {
            ...mapState(['common'])
        },
        methods: {
            init(row) {
                this.row = row;
                this.dialogVisible = true;
            },
            submit() {
                this.loading=true;
                del(this.row.id, 1).then(res => {
                    this.loading=false;
                    if(res.data.success){
                        this.dialogVisible = false;
                        this.$message({
                            type: "success",
                            message: res.data.msg
                        });
                        this.$emit('getData',1)
                        this.$store.dispatch('update_emailList')
                        if(this.row.emailAddr==this.common.currentEmail){
                            this.$store.commit('SAVECURRENTEMAIL', '');
                        }
                        this.bus.$emit('refreshEmailAddr','');
                        this.bus.$emit('refreshEmailNum')
                    }
                }).catch(err => {
                    this.loading=false;
                });
            }
        }
    }
</script>

<style scoped lang="scss">
  .dialog-bind {
    .content {
      width: 410px;
      margin: 0 auto;
      h1{
        font-weight: normal;
        font-size:16px;
        line-height: 40px;
        color: #232323;
      }
      p{
        line-height: 25px;
        color: #6a6a6a;
      }
    }
  }
</style>
